/*
 * Instruction55.java
 *
 * Created on March 22, 2007, 9:19 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package moto9s12sim;

/**
 *
 * @author Fergus Earnshaw
 */
public class Instruction55 extends Instruction{
    
    /** Creates a new instance of Instruction55 */
    public Instruction55() {
        this.strAssemblyCode = "ROLB";
        this.bCodes = new byte[1];
        this.bCodes[0] = (byte)Integer.parseInt("55",16);
    }
    
    public boolean excute(M9S12 cpu)
    {
        this.shAddr = cpu.PC.getRegister();
        cpu.PC.inc();
        byte bShft, bB;
        //First check the Carry bit to se what to shift.
        
        if (cpu.CC.getC())
        {
            bShft = (byte)0x01;
        }
        else
        {
            bShft = (byte)0x00;
        }
        //Next check to see what gets shifted out and set the carry bit.
        cpu.CC.setC(cpu.B.getRegister() < 0);
        //Now shift the register
        
        bB = cpu.B.getRegister();
        bB = (byte)(bB << 1);
        bB = (byte)(bB|bShft);
        cpu.B.setRegister(bB);
        //SET FLAGS
        cpu.CC.setN(cpu.B.getRegister() < (byte)0);
        cpu.CC.setZ(cpu.B.getRegister()==0);
        //cpu.CC.setV();
        
        printInstruction(cpu);
        //I think the first invalid instruction should halt excution
        return true;
    }  
    
}
